package com.bawei.common.adapter

import android.graphics.Color
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.bawei.image.ImgLoader
import com.bawei.image.option.ImageOptions

/**
 * Author: Jason Zhang
 * Date: 2024/5/8
 * Desc: 绑定适配器
 */
object CommonBindingAdapter {

    @JvmStatic
    @BindingAdapter("imageUrl")
    fun loadUrlImage(imageView: ImageView, url: String){
        if(!url.isNullOrEmpty()){
            ImgLoader.build().loadUrlIntoImageView(imageView.context,url, imageView, ImageOptions.setCommonImage(true).build())
        }
    }

    @JvmStatic
    @BindingAdapter("imageCircleUrl")
    fun loadUrlCircleImage(imageView: ImageView, url: String){
        if(!url.isNullOrEmpty()){
            ImgLoader.build().loadUrlIntoImageView(imageView.context,url, imageView, ImageOptions.setCircleImage(true).build())
        }
    }

    @JvmStatic
    @BindingAdapter("bgColor")
    fun loadBgColor(imageView: ImageView, colorStr: String){
        if(!colorStr.isNullOrEmpty()){
            imageView.setBackgroundColor(Color.parseColor(colorStr))
        }
    }

}